package com.xigua.JucOfBeautiful.chapterOne.yield1_6;

import com.xigua.JucOfBeautiful.chapterOne.trreadCreateAndRun1_2.ThreadTest;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/1/2222:59
 */
public class YieldTest implements Runnable {

    public YieldTest(){
        Thread thread = new Thread(this);
        thread.start();
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            if (i%5==0){
                System.out.println(Thread.currentThread()+"yield cpu...");
                Thread.yield();
            }
        }
        System.out.println(Thread.currentThread()+"is over");
    }

    public static void main(String[] args) {
        new YieldTest();
        new YieldTest();
        new YieldTest();
    }
}
